<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test后台</title>
</head>
<body>

<input type="file" id="file"/>

<button id="submit">获取永久mediaid</button>

<button id="submit2">上传图文素材</button>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
const input = document.querySelector('#file');
const btn = document.querySelector('#submit');
const btn2 = document.querySelector('#submit2');

const request = axios.create({
  baseURL: '',
  timeout: 5000,
  transformRequest: [
    data => {
      let arr = [];
      for(let i in data) {
        if(data.hasOwnProperty(i)) {
          arr.push(encodeURIComponent(i) + "=" + encodeURIComponent(data[i]));
        }
      }
      return arr.join("&");
    }
  ]
});

btn.onclick = () => {

  const file = input.files[0];

  const data = new FormData();
  data.append('file', file);

  axios.post('/uploadMedia', data);
}

btn2.onclick = () => {

  axios.post('/sendMessage');
}

</script>

</body>
</html>